<?php
/**
 * @ClassName: Memberlevelsetting
 * @Description: 等级设置
 * @author: gydtrade
 * @Date: 2024-09-09 22:39
 * @Version: V1.0.0
 */

namespace app\admin\controller;

use app\common\model;
use think\Controller;
use tpext\builder\common\Builder;

class Memberlevelsetting extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    function index()
    {
        // 获取数据
        $config_data = model\SystemConfig::where('config_tab_id', 7)->find();

        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
            $res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/memberlevelsetting/index'));
            } else {
                $this->error('修改失败', url('/admin/memberlevelsetting/index'));
            }
        }

        $builder = Builder::getInstance('等级设置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);

        $form->radio('member_level_enable', '用户等级启用')->help('商城用户等级功能开启|关闭')->default(0)->options([0 => '关闭', 1 => '开启'])->when(1)->with(
            $form->number('order_points_ratio', '下单赠送用户经验比例（实际支付1元赠送多少经验）')->help('下单赠送用户经验比例（实际支付1元赠送多少经验）')->default(1),
            $form->number('sign_points', '签到赠送用户经验值')->help('签到赠送用户经验值')->default(10),
            $form->number('invite_new_users_points', '邀请新用户赠送用户经验值')->help('邀请一个新用户赠送用户经验值')->default(20)
        );

        return $builder;
    }

}